package evostar.result;


import lombok.Data;

@Data
public class Result<T> {
    private int code;
    private String msg;
    private T data;

    public static <T> Result<T> success(T data) {
        return new Result<>(data);
    }

    public static <T> Result<T> error(CodeMsg codeMsg) {
        return new Result(codeMsg);
    }

    public Result(T data) {
        this.code = CodeMsg.SUCCESS.getCode();
        this.msg = CodeMsg.SUCCESS.getMsg();
        this.data = data;
    }

    public Result(CodeMsg msg) {
        this.code = msg.getCode();
        this.msg = msg.getMsg();
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
}
